home *** CD-ROM | disk | FTP | other *** search
/ The 640 MEG Shareware Studio 2 / The 640 Meg Shareware Studio CD-ROM Volume II (Data Express)(1993).ISO / prog / mod2tutb.zip / RECURSON.MOD < prev    next >
Text File  |  1989-01-18  |  773b  |  39 lines

  1.                                          (* Chapter 5 - Program 7 *)
  2. MODULE Recurson;
  3.  
  4. FROM InOut IMPORT WriteString, WriteInt, WriteLn;
  5.  
  6. VAR Count : INTEGER;
  7.  
  8. PROCEDURE PrintAndDecrement(Index : INTEGER);
  9. BEGIN
  10.    WriteString("The value of the Index is");
  11.    WriteInt(Index,5);
  12.    WriteLn;
  13.    Index := Index - 1;
  14.    IF Index > 0 THEN
  15.       PrintAndDecrement(Index);
  16.    END;
  17. END PrintAndDecrement;
  18.  
  19. BEGIN    (* Main program *)
  20.    Count := 7;
  21.    PrintAndDecrement(Count);
  22. END Recurson.
  23.  
  24.  
  25.  
  26.  
  27. (* Result of execution
  28.  
  29. The value of the Index is    7
  30. The value of the Index is    6
  31. The value of the Index is    5
  32. The value of the Index is    4
  33. The value of the Index is    3
  34. The value of the Index is    2
  35. The value of the Index is    1
  36.  
  37. *)
  38.  
  39.